import 'package:flutter/material.dart';
import 'package:vmall_app/models/goods.dart';

class Guarantee extends StatelessWidget {
  final int goodsId;

  const Guarantee({Key key, this.goodsId}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var itemList = getGoodsById(this.goodsId).guaranteeItemList;
    List<Widget> items = [];
    if (itemList != null) {
      itemList.forEach((f) {
        items.add(GuaranteeItemWidget(
          title: f.title,
          description: f.descirption,
          icon: f.iconData,
        ));
      });
    }

    return Container(
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(10), topRight: Radius.circular(10))),
      child: Column(
        children: [
          Container(
            padding: const EdgeInsets.all(5),
            child: Stack(
              children: <Widget>[
                Center(
                  child: Container(
                    padding: const EdgeInsets.all(5),
                    child: Text(
                      '基础保障',
                      style: TextStyle(
                          fontWeight: FontWeight.w400,
                          color: Colors.black.withOpacity(0.7)),
                    ),
                  ),
                ),
                InkWell(
                  enableFeedback: true,
                  onTap: () {
                    Navigator.of(context).pop();
                  },
                  child: Align(
                    alignment: AlignmentDirectional.topEnd,
                    child: Icon(Icons.cancel, color: Colors.grey, size: 20),
                  ),
                )
              ],
            ),
          ),
          Expanded(
              child: ListView(
            children: <Widget>[...items],
          )),
        ],
      ),
    );
  }
}

class GuaranteeItemWidget extends StatelessWidget {
  final String title;
  final IconData icon;
  final String description;

  const GuaranteeItemWidget({Key key, this.title, this.icon, this.description})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: <Widget>[
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                children: <Widget>[
                  Icon(
                    this.icon,
                    color: Colors.red,
                  ),
                  Text(
                    this.title,
                    style: TextStyle(fontWeight: FontWeight.w300, fontSize: 12),
                  ),
                ],
              ),
              Padding(
                padding: const EdgeInsets.only(
                    left: 20, top: 8.0, bottom: 8, right: 8),
                child: RichText(
                  text: TextSpan(
                      text: this.description,
                      style: TextStyle(
                          color: Colors.grey,
                          fontSize: 11,
                          fontWeight: FontWeight.w400)),
                ),
              )
            ],
          )
        ],
      ),
    );
  }
}
